
 
 F u n c t i o n :   t o g g l e C l a s s ( d o m E l e m e n t O r N o d e A r r a y O r C S S S e l e c t o r ,   s t r i n g C l a s s N a m e ,   b o o l F o r c e S t a t e ,   f u n c t i o n C a l l b a c k ( c u r r e n t S t a t e ) ) 
 
 
 
 D e s c r i p t i o n :   T o g g l e s   a   c l a s s   n a m e   o n   t h e   s p e c i f i e d   e l e m e n t   o r   s e t   o f   m a t c h i n g   e l e m e n t s . 
 
 
 
 R e t u r n s :   d o m E l e m e n t   o r   m a t c h i n g   n o d e   a r r a y ,   o r   $ A   o b j e c t   i f   c h a i n e d . 
 
 
 
 N o t e :   W h e n   t h e   b o o l F o r c e S t a t e   p a r a m e t e r   i s   o m i t t e d ,   t o g g l e C l a s s   w i l l   a u t o m a t i c a l l y   t o g g l e   i t s e l f   u s i n g   t h e   c u r r e n t   s t a t e .   O t h e r w i s e ,   t h e   b o o l F o r c e S t a t e   p a r a m e t e r   w i l l   f o r c e   a   t r u e   o r   f a l s e   s t a t e   t o   b e   s e t .   T h e   c a l l b a c k   f u n c t i o n   m a y   b e   u s e d   t o   p e r f o r m   a d d i t i o n a l   a c t i o n s   r e l a t i n g   t o   t h e   t o g g l e   s t a t e .   W h e n   t h e   c a l l b a c k   f u n c t i o n   i s   p a s s e d   a s   t h e   t h i r d   p a r a m e t e r ,   t h e n   b o o l F o r c e S t a t e   i s   u n d e f i n e d . 
 
 
 
 E x a m p l e : 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   b e t w e e n   t r u e   o r   f a l s e   b a s e d   o n   t h e   c u r r e n t   s t a t e   o f   t h e   c l a s s   n a m e   o n   t h e   s p e c i f i e d   e l e m e n t . 
 
 v a r   m y E l e m e n t   =   $ A . t o g g l e C l a s s ( d o m E l e m e n t ,   " s e l e c t e d " ) ; 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   t h e   s t a t e   t o   t r u e   a n d   s e t   c l a s s   n a m e   o n   t h e   s p e c i f i e d   e l e m e n t . 
 
 v a r   m y E l e m e n t   =   $ A . t o g g l e C l a s s ( d o m E l e m e n t ,   " s e l e c t e d " ,   t r u e ) ; 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   t h e   s t a t e   t o   f a l s e   a n d   r e m o v e   c l a s s   n a m e   o n   m u l t i p l e   e l e m e n t s . 
 
 v a r   m y E l e m e n t s A r r a y   =   $ A . t o g g l e C l a s s ( [ d o m E l e m e n t 1 ,   d o m E l e m e n t 2 ] ,   " b u t t o n - p r e s s e d " ,   f a l s e ) ; 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   t h e   s t a t e   t o   f a l s e   a n d   r e m o v e   c l a s s   n a m e   o n   m u l t i p l e   e l e m e n t s   r e f e r e n c e d   u s i n g   a   C S S   s e l e c t o r . 
 
 v a r   m y E l e m e n t s A r r a y   =   $ A . t o g g l e C l a s s ( ' n a v . l e f t   b u t t o n [ a r i a - p r e s s e d = " f a l s e " ] ' ,   " b u t t o n - p r e s s e d " ,   f a l s e ) ; 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   b e t w e e n   t r u e   o r   f a l s e   b a s e d   o n   t h e   c u r r e n t   s t a t e   o f   t h e   c l a s s   n a m e   o n   t h e   s p e c i f i e d   e l e m e n t ,   a n d   r u n   a   c a l l b a c k   t o   p e r f o r m   a d d i t i o n a l   a c t i o n s . 
 
 v a r   m y E l e m e n t   =   $ A . t o g g l e C l a s s ( d o m E l e m e n t ,   " s e l e c t e d " ,   f u n c t i o n ( a c t i v e S t a t e )   { 
 
     / /   D o   s o m e t h i n g   w h e n   a c t i v e S t a t e   i s   t r u e   o r   f a l s e . 
 
     / /   ' t h i s '   =   t h e   D O M   e l e m e n t   b e i n g   t o g g l e d . 
 
 } ) ; 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   t h e   s t a t e   t o   f a l s e   a n d   r e m o v e   c l a s s   n a m e   o n   t h e   s p e c i f i e d   e l e m e n t ,   a n d   r u n   a   c a l l b a c k   t o   p e r f o r m   a d d i t i o n a l   a c t i o n s . 
 
 v a r   m y E l e m e n t   =   $ A . t o g g l e C l a s s ( d o m E l e m e n t ,   " s e l e c t e d " ,   f a l s e ,   f u n c t i o n ( a c t i v e S t a t e )   { 
 
     / /   D o   s o m e t h i n g   w h e n   a c t i v e S t a t e   i s   t r u e   o r   f a l s e . 
 
     / /   ' t h i s '   =   t h e   D O M   e l e m e n t   b e i n g   t o g g l e d . 
 
 } ) ; 
 
 
 
 / /   O r   t h e   s a m e   u s i n g   c h a i n i n g 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   t h e   s t a t e   t o   f a l s e   a n d   r e m o v e   c l a s s   n a m e   o n   m u l t i p l e   e l e m e n t s . 
 
 v a r   m y C h a i n   =   $ A ( [ d o m E l e m e n t 1 ,   d o m E l e m e n t 2 ] ) . t o g g l e C l a s s ( " b u t t o n - p r e s s e d " ,   f a l s e ) ; 
 
 
 
 / /   A u t o m a t i c a l l y   t o g g l e   t h e   s t a t e   t o   f a l s e   a n d   r e m o v e   c l a s s   n a m e   o n   m u l t i p l e   e l e m e n t s   r e f e r e n c e d   u s i n g   a   C S S   s e l e c t o r . 
 
 v a r   m y C h a i n   =   $ A ( ' n a v . l e f t   b u t t o n [ a r i a - p r e s s e d = " f a l s e " ] ' ) . t o g g l e C l a s s ( " b u t t o n - p r e s s e d " ,   f a l s e ) ; 
 
 
 
 / /   T o   r e t u r n   t h e   m o d i f i e d   e l e m e n t   w i t h i n   a   c h a i n ,   u s e   t h e   " r e t u r n ( ) "   m e t h o d . 
 
 
 
 v a r   m y E l e m e n t   =   m y C h a i n . r e t u r n ( ) ; 
 
 